package com.iyao_app.http;

import com.iyao_app.MyApplication;

import java.io.File;
import java.util.concurrent.TimeUnit;

import okhttp3.Cache;
import okhttp3.OkHttpClient;

/**
 * 作者 :  胡家兵
 * 时间 :  2017/11/17.
 */

public class OkUtil {

    public static OkHttpClient getOkHttpClient() {

        File file = new File(MyApplication.getInstance().getCacheDir(), "com.iyao_app");
        Cache cache = new Cache(file, 10 * 1024 * 1024);

        OkHttpClient client = new OkHttpClient.Builder().cache(cache)
                .connectTimeout(10, TimeUnit.SECONDS)
                .readTimeout(30, TimeUnit.SECONDS)
                .writeTimeout(10, TimeUnit.SECONDS)
                .retryOnConnectionFailure(true)
//                .pingInterval(30, TimeUnit.SECONDS)
                .build();
        return client;
    }
}
